Swap estimate
The Swap estimate API is used to fetch estimated amount for a swap transaction. By invoking this API, users can obtain an estimate amount of the swap transaction.
Method: POST
{{URL}}/jsonrpc
Headers
Name | Value |
---|---|
Content-Type | application/json |
Example
Payload Parameters
Parameter | Description |
---|---|
id Mandatory | String Represents the unique identifier associated with the swap estimate request. Ex: "701001" |
asset Mandatory | String Represents the source asset for the swap transaction. Ex: "SRT" |
issuer Mandatory | String Represents the issuer of the source asset. Ex: "" |
amount Mandatory | String Represents the amount of the source asset to be swapped. Ex: "10" |
destinationAsset Mandatory | String Represents the destination asset for the swap transaction. Ex: "USDC" |
destinationIssuer Mandatory | String Represents the issuer of the destination asset. Ex: "GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW" |
fee Mandatory | String Represents the fee amount for the swap transaction. Ex: "100" |
- cURL
- C#
- Go
- NodeJs
curl --location '{{url}}/rpc/WalletService/SwapEstimate' \
--header 'DiviceID: 8020' \
--header 'Signature: keyId=8020,algorithm=ecdsa-sha256,signature=MEUCIQCNi1vjPf/HpI9R2DXnc0Zt1s6YmWyA4H1x813lJ+tuDgIgB+lrc+iCMyTUGiraG9kGKNDXYiz7RfBBtifr5wUQs54=' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tFbWFpbH19Ont7UGFzc3dvcmR9fQ==' \
--data '{"id":"701001","asset":"XLM","issuer":"","amount":"10","destinationAsset":"USDC","destinationIssuer":"GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW","fee":"100"}'
var options = new RestClientOptions("{{url}}")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/fednowbackend/rpc/WalletService/SwapEstimate", Method.Post);
request.AddHeader("DiviceID", "8020");
request.AddHeader("Signature", "keyId=8020,algorithm=ecdsa-sha256,signature=MEUCIQCNi1vjPf/HpI9R2DXnc0Zt1s6YmWyA4H1x813lJ+tuDgIgB+lrc+iCMyTUGiraG9kGKNDXYiz7RfBBtifr5wUQs54=");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Basic e3tFbWFpbH19Ont7UGFzc3dvcmR9fQ==");
var body = @"{
" + "\n" +
@" ""id"": ""701001"",
" + "\n" +
@" ""asset"": ""XLM"",
" + "\n" +
@" ""issuer"": """",
" + "\n" +
@" ""amount"": ""10"",
" + "\n" +
@" ""destinationAsset"": ""USDC"",
" + "\n" +
@" ""destinationIssuer"": ""GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW"",
" + "\n" +
@" ""fee"": ""100""
" + "\n" +
@"}";
request.AddStringBody(body, DataFormat.Json);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "{{url}}/rpc/WalletService/SwapEstimate"
method := "POST"
payload := strings.NewReader(`{`+"
"+`
"id": "701001",`+"
"+`
"asset": "XLM",`+"
"+`
"issuer": "",`+"
"+`
"amount": "10",`+"
"+`
"destinationAsset": "USDC",`+"
"+`
"destinationIssuer": "GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW",`+"
"+`
"fee": "100"`+"
"+`
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("DiviceID", "8020")
req.Header.Add("Signature", "keyId=8020,algorithm=ecdsa-sha256,signature=MEUCIQCNi1vjPf/HpI9R2DXnc0Zt1s6YmWyA4H1x813lJ+tuDgIgB+lrc+iCMyTUGiraG9kGKNDXYiz7RfBBtifr5wUQs54=")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Basic e3tFbWFpbH19Ont7UGFzc3dvcmR9fQ==")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': '{{url}}',
'path': '/fednowbackend/rpc/WalletService/SwapEstimate',
'headers': {
'DiviceID': '8020',
'Signature': 'keyId=8020,algorithm=ecdsa-sha256,signature=MEUCIQCNi1vjPf/HpI9R2DXnc0Zt1s6YmWyA4H1x813lJ+tuDgIgB+lrc+iCMyTUGiraG9kGKNDXYiz7RfBBtifr5wUQs54=',
'Content-Type': 'application/json',
'Authorization': 'Basic e3tFbWFpbH19Ont7UGFzc3dvcmR9fQ=='
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"id": "701001",
"asset": "XLM",
"issuer": "",
"amount": "10",
"destinationAsset": "USDC",
"destinationIssuer": "GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW",
"fee": "100"
});
req.write(postData);
req.end();
Body
{
"id": "701001",
"asset": "XLM",
"issuer": "",
"amount": "10",
"destinationAsset": "USDC",
"destinationIssuer": "GDBTV4ULJ5HG2N6YJSDGVL2XPQY3F33K2U7M6MGPJJ3KIG6EFENF56QW",
"fee": "100"
}
Response: 200
Response Parameters
Parameter | Description |
---|---|
estimateAmount | String Represents the estimated amount of the destination asset to be received. Ex: "9.9800399" |
path | Array |
quotationId | String Represents the unique identifier for the swap quotation. Ex: "865001" |
{
"estimateAmount": "9.9800399",
"path": [],
"quotationId": "865001"
}